package lesson.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lesson.entity.Academy;
import lesson.entity.Team;
import lesson.service.AcademyService;
import lesson.service.TeamService;
import lesson.vo.AcademyVo;
import lesson.vo.DataView;
import lesson.vo.TeamVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: Wanzhen
 * @Date: 2022/6/13-22:48
 */
@RestController
//@Controller
//@RequestMapping("/team")
public class TeamController {

    @Autowired
    public TeamService teamService;

    @GetMapping("/team/listTeam")
    public DataView listTeam(TeamVo teamVo){
        QueryWrapper<Team> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(teamVo.getName()),"name",teamVo.getName());
        IPage<Team> iPage = new Page<>(teamVo.getPage(), teamVo.getLimit());
        teamService.page(iPage, queryWrapper);
        return new DataView(iPage.getTotal(), iPage.getRecords());
    }

    /**
     * 新增或修改
     * @return
     */
    @PostMapping("/team/addOrUpdate")
    public DataView addOrUpdate(Team team){
        teamService.saveOrUpdate(team);
        DataView dataView = new DataView();
        dataView.setCode(200);
        dataView.setMsg("新增或修改班级成功");
        return dataView;
    }

    @DeleteMapping("/team/deleteById")
    public DataView deleteById(Integer id){
        teamService.removeById(id);
        DataView dataView = new DataView();
        dataView.setCode(200);
        dataView.setMsg("删除班级成功");
        return dataView;
    }

}
